/**
 * Copyright (c) 2014- 2015 YCY Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package com.jkwzms.system.resource.entity.tmp;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.annotation.JSONField;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

/**
 * 界面是那个使用的菜单对象
 * 
 * @author JackLiang
 * @date 2015-3-4
 * @version 1.0.0
 */
public class Menu implements Serializable {

    private static final long   serialVersionUID = 1017182651369074493L;

    private Long                id;

    @JSONField(name = "text")
    private String              name;

    @JSONField(name = "iconCls")
    private String              icon;

    private String              url;

    private Map<String, Object> attributes       = Maps.newHashMap();

    private List<Menu>          children;

    public Menu(Long id, String name, String icon, String url){
        this.id = id;
        this.name = name;
        this.icon = icon;
        this.url = url;
        this.attributes.put("target", "");
        this.attributes.put("url", url);
    }

    // setter getter
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Map<String, Object> getAttributes() {
        return attributes;
    }

    public void setAttributes(Map<String, Object> attributes) {
        this.attributes = attributes;
    }

    public List<Menu> getChildren() {
        if (children == null) {
            children = Lists.newArrayList();
        }
        return children;
    }

    public void setChildren(List<Menu> children) {
        this.children = children;
    }

    /**
     * @return
     */

    @JSONField(serialize = false)
    public boolean isHasChildren() {
        return !getChildren().isEmpty();
    }

    @Override
    public String toString() {
        return "Menu{" + "id=" + id + ", name='" + name + '\'' + ", icon='" + icon + '\'' + ", url='" + url + '\''
               + ", children=" + children + '}';
    }
}
